package main

import (
	"fmt"
	"math"
	"math/cmplx"
)

var (
	name = "小虾米"
)

func main() {
	variableZeroValue()
	variableInitialValue()
	variableTypeDeduction()
	variableShorter()
	euler()
	triangle()
	variableConst()
	fmt.Println(name + " main end")
}

func variableEnum() {
	const (
		cpp = iota
		_
		java
		python
		golang
	)

	const (
		b = 1 << (10 * iota)
		kb
		mb
		gb
		tb
		pb
	)
}

func variableConst() {
	const filename string = "abc.ini"
	const a, b = 3, 4
	var c int
	c = int(math.Sqrt(a*a + b*b))
	fmt.Println("c的计算结果是：", c)
}

func euler() {
	//复数的表示
	c := 3 + 4i
	abs := cmplx.Abs(c)
	fmt.Println("abs :", abs)

	rs := cmplx.Pow(math.E, 1i*math.Pi) + 1
	fmt.Println("欧拉公式结果 :", rs)
	fmt.Println("e的另外一种写法 :", cmplx.Exp(1i*math.Pi)+1)
	fmt.Printf("格式化 : %3.f\n", cmplx.Exp(1i*math.Pi)+1)
}

func triangle() {
	var a, b int = 3, 4
	var c int
	//类型转换是强制的
	c = int(math.Sqrt(float64(a*a + b*b)))
	fmt.Println("c :", c)
}

func variableZeroValue() {
	var a int
	var s string
	fmt.Println(a)
	fmt.Printf("a:%d s:%q \n", a, s)
}

func variableInitialValue() {
	var a, b int = 28, 38
	var s string = "hello world"
	fmt.Println(a)
	fmt.Printf("a:%d b:%d s:%q \n", a, b, s)
}

func variableTypeDeduction() {
	var a, b, s = 28, 38, "hello world"
	fmt.Println(a)
	fmt.Printf("a:%d b:%d s:%q \n", a, b, s)
}

func variableShorter() {
	a, b, s, flag := 28, 38, "hello world", true
	a = 126
	fmt.Printf("a:%d b:%d s:%q flag:%v \n", a, b, s, flag)
}
